import { prisma } from "@/lib/prisma"
import { IncomeList } from "@/components/income/income-list"
import { IncomeHeader } from "@/components/income/income-header"
import { Metadata } from "next"
import { SerializedFinanceRecord } from "@/types"

export const metadata: Metadata = {
  title: "收入记录 - 商场销售系统",
  description: "收入记录页面",
}

export default async function IncomePage() {
  const records = await prisma.financeRecord.findMany({
    where: {
      type: 'INCOME'
    },
    orderBy: {
      createdAt: 'desc'
    }
  })

  // 序列化数据，确保 Decimal 类型被转换为字符串
  const serializedRecords: SerializedFinanceRecord[] = records.map(record => ({
    ...record,
    amount: record.amount.toString(),
    createdAt: record.createdAt.toISOString(),
    updatedAt: record.updatedAt.toISOString()
  }))

  return (
    <div className="space-y-4 p-8">
      <IncomeHeader />
      <IncomeList records={serializedRecords} />
    </div>
  )
} 